<template>
    <div class="qingwu">
        <div class="admin_table_page_title">订单列表</div>
        <div class="unline underm"></div>

        <div class="admin_table_handle_btn">
            <a-form layout="inline" :form="form" @submit="handleSubmit">
                <a-form-item label="用户ID">
                    <a-input  v-model="user_id" placeholder="用户ID"/>
                </a-form-item>

                <a-form-item label="状态">
                    <a-select @change="handleChange" style="width: 120px" default-value="全部" v-model="type">
                        <a-select-option :value="value.id" v-for="(value,index) in type_lists"
                                         :key="index">
                            {{ value.title }}
                        </a-select-option>
                    </a-select>
                </a-form-item>
                <a-form-model-item>
                    <a-button icon="search" @click="search">
                        查询
                    </a-button>
                </a-form-model-item>
            </a-form>
        </div>

        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false"
                     :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="id">
                <span slot="action" slot-scope="rows">
                    <a-button icon="file-search"
                              @click="$router.push('/Estate/flea_order/form/'+rows.id)">查看详情</a-button>
                </span>

                <span slot="house_type" slot-scope="rows">
                    <div class="admin_goods_pic_txt">
                        <div>{{rows.more_option.户型}}</div>
                    </div>
                </span>

                <span slot="type" slot-scope="rows">
                    <div class="admin_goods_pic_txt">
                        <div>{{rows.type == 1 ? '整租' : '合租'}}</div>
                    </div>
                </span>
            </a-table>
            <div class="admin_pagination" v-if="pages>0">
                <a-pagination v-model="params.page" :page-size.sync="params.limit" :total="pages" @change="onChange"
                              show-less-items/>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        components: {},
        props: {},
        data() {
            return {
                params: {
                    page: 1,
                    limit: 20,
                },
                pages: 0, //总页数
                selectedRowKeys: [], // 被选择的行
                columns: [
                    {title: '#', dataIndex: 'id', fixed: 'left'},
                    {title: '用户ID', dataIndex: 'user_id'},
                    {title: '订单号', dataIndex: 'order_sn'},
                    {title: '订单状态', dataIndex: 'state_text'},
                    {title: '订单总金额', dataIndex: 'total_amount'},
                    {title: '商品标题', dataIndex: 'goods.goods_name'},
                    {title: '下单时间', dataIndex: 'created_at'},
                    {title: '支付时间', dataIndex: 'pay_at'},
                    {title: '操作', key: 'id', fixed: 'right', scopedSlots: {customRender: 'action'}},
                ],
                list: [],
                type: '',
                user_id: '',
                type_lists: [{id: 0, title: '全部'}, {id: 1, title: '代付款'}, {id: 2, title: '待取货'}, {
                    id: 3,
                    title: '待评价'
                }, {id: 4, title: '已完成'}]
            };
        },
        watch: {},
        computed: {},
        methods: {
            // 选择框被点击
            onSelectChange(selectedRowKeys) {
                this.selectedRowKeys = selectedRowKeys;
            },
            // 选择分页
            onChange(e) {
                this.params.page = e;
                this.onload();
            },
            onload() {
                this.$get(this.$api.estateFleaOrder, this.params).then(res => {
                    this.pages = res.data.pages;
                    this.list = res.data.data;
                });
            },
            // 搜索
            search() {
                this.params['state'] = this.type;
                this.params['user_id'] = this.user_id;
                this.$get(this.$api.estateFleaOrder, this.params).then(res => {
                    this.pages = res.data.pages;
                    this.list = res.data.data;
                });
            },
        },
        created() {
            this.onload();
        },
        mounted() {
        }
    };
</script>
<style lang="scss" scoped>

</style>
